<template>
	<view class="container">
		<view class="address_view" @click="tenantAction()">
			{{ tenantName }}
			<image src="@/static/images/smartLock/addressIcon.png" mode=""
				style="width: 30rpx;height: 25rpx;margin-left: 10rpx;"></image>
		</view>
		<view class="tabs_view">
			<u-tabs-swiper ref="tabs" :list="tabsList" :is-scroll="false" active-color="#324DEC" :current="current"
				@change="tabsChange"></u-tabs-swiper>
			<!-- <view class="clearRead_view Text8A" @click="clearReadAction()">
				清除未读
			</view> -->
		</view>
		<view class="list_view">
			<view class="item_view" v-for="(item,index) in dataList" :key="index" @click="detailAction(item)">
				<view class="item_top_view">
					<view class="top_left_view">
						<image src="@/static/images/smartLock/clock.png" mode="" style="width: 20rpx;height: 20rpx;">
						</image>
						<view style="margin-left: 10rpx;">
							{{ item.sendTime }}
						</view>
					</view>
					<!-- <view class="top_right_view" v-if="item.readFlag===1">
						· 未读
					</view> -->
				</view>
				<u-line color="#E8E8E8" margin="10rpx" />
				<view class="item_bottom_view">
					<view class="left_view">
						<view class="icon_view">
							<image v-if="item.msgCategory=='3'" :src="alarmIcon" mode=""
								style="border-radius: 10rpx;width: 100%;height: 100%;">
							</image>
						</view>
						<view class="content_view">
							<view class="Text33">
								{{ item.title }}
							</view>
							<view class="Text66">
								{{ item.deviceName }}
							</view>
						</view>
					</view>
					<view class="right_view">
						<!-- <view class="">
							2023/11/15 13:30
						</view> -->
						<u-icon name="arrow-right"></u-icon>
					</view>
				</view>
			</view>
		</view>
		<u-empty text="暂无数据" mode="list" v-if="dataList.length==0" :margin-top="300"></u-empty>
	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			return {
				keyword: '',
				tenantName: '',
				tenantId: '',
				doorIcon: '/static/images/smartLock/doorIcon.png',
				lockIcon: '/static/images/smartLock/lockIcon.png',
				alarmIcon: '/static/images/smartLock/alarmIcon.png',
				tabsList: [{
					name: '今天'
				}, {
					name: '最近三天'
				}, {
					name: '最近一周'
				}],
				current: 0, // tabs组件的current值，表示当前活动的tab选项
				dataList: [],
				pageNum: 1,
				pageSize: 10,
				total: 0,
				emptyPage: false,
			}
		},
		onShow() {
			var that = this
			uni.$on('seletedTenant', function(e) {
				that.tenantName = e.tenantName
				that.tenantId = e.tenantId
				that.pageNum = 1
				that.getNoticeListData()
			})
		},
		onLoad() {
			let sUserInfo = this.$storage.getStorageDataSync("sUserInfo")
			this.tenantId = sUserInfo.tenantId
			this.tenantName = sUserInfo.tenantName
			this.getNoticeListData()
		},
		methods: {
			// tabs通知swiper切换
			tabsChange(index) {
				this.current = index;
				this.pageNum = 1
				this.getNoticeListData()
			},
			tenantAction() {
				this.$Router.push({
					name: 'tenantIndex'
				})
			},
			clearReadAction() {
				this.$show.toastMessage('全部已读！');
			},
			detailAction(item) {
				this.$Router.push({
					name: 'messageDetail',
					params: {
						id: item.id
					}
				})
			},
			onPullDownRefresh() {
				this.pageNum = 1
				this.getNoticeListData()
			},
			onReachBottom() {
				if (this.total <= this.pageNum * this.pageSize) {
					return
				}
				this.pageNum += 1
				this.getNoticeListData()
			},
			getNoticeListData() {
				var that = this
				this.$apis.getNoticeList({
					tenantId: this.tenantId,
					queryTimeType: this.current + 1,
					pageNum: this.pageNum,
					pageSize: this.pageSize
				}).then(result => {
					uni.stopPullDownRefresh();
					if (result.res.data.code == '200') {
						if (that.pageNum == 1) {
							that.dataList = [] //如果是第一页需手动制空列表
							if (result.res.data.rows.length == 0) that.emptyPage = true
						}
						that.total = result.res.data.total
						that.dataList = that.dataList.concat(result.res.data.rows)
					} else {
						that.$show.toastMessage(result.res.data.msg);
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		min-height: 100vh;
		box-sizing: border-box;
		background-color: #F8F8F8;
	}

	.address_view {
		padding: 10rpx 20rpx;

		display: flex;
		flex-direction: row;
		align-items: center;
		background-color: #FFFFFF;
	}

	.tabs_view {
		padding-right: 20rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		background-color: #FFFFFF;

		.clearRead_view {
			width: 300rpx;
			display: flex;
			justify-content: flex-end;
			align-items: center;
		}
	}

	.list_view {
		padding: 20rpx;
		padding-top: 0;

		.item_view {
			display: flex;
			flex-direction: column;
			justify-content: center;
			// align-items: center;
			padding: 20rpx;
			margin: 20rpx 0;
			background-color: #FFFFFF;
			border-radius: 10rpx;

			.item_top_view {
				width: 100%;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;

				.top_left_view {
					display: flex;
					flex-direction: row;
					align-items: center;
				}

				.top_right_view {
					font-size: 24rpx;
					color: #C01212;
				}
			}

			.item_bottom_view {
				width: 100%;
				margin-top: 5rpx;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;

				.left_view {
					display: flex;
					flex-direction: row;

					.icon_view {
						width: 80rpx;
						height: 80rpx;
					}

					.content_view {
						margin-left: 10px;
					}
				}

				.right_view {
					display: flex;
					flex-direction: row;
					justify-content: flex-start;
					align-items: flex-start;
				}
			}
		}
	}
</style>